
<h1><span class="yiyi-st" id="yiyi-13">numpy.random.RandomState.negative_binomial</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.negative_binomial.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.negative_binomial.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="method">
<dt id="numpy.random.RandomState.negative_binomial"><span class="yiyi-st" id="yiyi-14"> <code class="descclassname">RandomState.</code><code class="descname">negative_binomial</code><span class="sig-paren">(</span><em>n</em>, <em>p</em>, <em>size=None</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-15">从负二项分布绘制样本。</span></p>
<p><span class="yiyi-st" id="yiyi-16">样本从具有指定参数<em class="xref py py-obj">n</em>试验和<em class="xref py py-obj">p</em>成功概率的负二项分布中绘制，其中<em class="xref py py-obj">n</em>是&gt; 0和<em class="xref py py-obj"> p</em>在区间[0，1]中。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-17">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-18"><strong>n</strong>：int</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-19">参数，&gt; 0。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-20"><strong>p</strong>：float</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-21">参数，&gt; = 0和</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-22"><strong>size</strong>：int或tuple的整数，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-23">输出形状。</span><span class="yiyi-st" id="yiyi-24">如果给定形状是例如<code class="docutils literal"><span class="pre">（m，</span> <span class="pre">n，</span> <span class="pre">k）</span></code>，则<code class="docutils literal"><span class="pre"> m</span> <span class="pre">*</span> <span class="pre">n</span> <span class="pre">*</span> <span class="pre">k</span></code></span><span class="yiyi-st" id="yiyi-25">默认值为None，在这种情况下返回单个值。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-26">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-27"><strong>samples</strong>：int或ndarray of ints</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-28">绘制样品。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric"><span class="yiyi-st" id="yiyi-29">笔记</span></p>
<p><span class="yiyi-st" id="yiyi-30">负二项分布的概率密度为</span></p>
<div class="math">
<p></p>
</div><p><span class="yiyi-st" id="yiyi-31">其中<img alt="n-1" class="math" src="../../_images/math/6e838b52d1729b70e5a719aa3e2f5392b55175d7.png" style="vertical-align: -1px">是成功的数量，<img alt="p" class="math" src="../../_images/math/c5b47cd114d1cd218d587260b667ed59b7ace4a0.png" style="vertical-align: -3px">是成功的概率，而<img alt="N+n-1" class="math" src="../../_images/math/9fb51b97133b32727dc325327036e3ea59075680.png" style="vertical-align: -2px">是试验的数量。</span><span class="yiyi-st" id="yiyi-32">负二项分布给出了N + n-1次试验中n-1次成功和N次失败的概率，以及第（N + n）次试验的成功率。</span></p>
<p><span class="yiyi-st" id="yiyi-33">如果直到第三次出现“1”，第三个“1”之前出现的非“1”的数量的概率分布是负二项分布。</span></p>
<p class="rubric"><span class="yiyi-st" id="yiyi-34">参考文献</span></p>
<table class="docutils citation" frame="void" id="r172" rules="none">
<colgroup><col class="label"><col></colgroup>
<tbody valign="top">
<tr><td class="label"><span class="yiyi-st" id="yiyi-35"><a class="fn-backref" href="#id1">[R172]</a></span></td><td><span class="yiyi-st" id="yiyi-36">Weisstein，Eric W.“负二项分布”，来自MathWorld-Wolfram Web资源。</span><span class="yiyi-st" id="yiyi-37"><a class="reference external" href="http://mathworld.wolfram.com/NegativeBinomialDistribution.html">http://mathworld.wolfram.com/NegativeBinomialDistribution.html</a></span></td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="r173" rules="none">
<colgroup><col class="label"><col></colgroup>
<tbody valign="top">
<tr><td class="label"><span class="yiyi-st" id="yiyi-38"><a class="fn-backref" href="#id2">[R173]</a></span></td><td><span class="yiyi-st" id="yiyi-39">维基百科，“负二项分布”，<a class="reference external" href="http://en.wikipedia.org/wiki/Negative_binomial_distribution">http://en.wikipedia.org/wiki/Negative_binomial_distribution</a></span></td></tr>
</tbody>
</table>
<p class="rubric"><span class="yiyi-st" id="yiyi-40">例子</span></p>
<p><span class="yiyi-st" id="yiyi-41">从分布绘制样本：</span></p>
<p><span class="yiyi-st" id="yiyi-42">一个现实世界的例子。</span><span class="yiyi-st" id="yiyi-43">一家公司钻探野猫石油勘探井，每个井的估计成功概率为0.1。</span><span class="yiyi-st" id="yiyi-44">对于每个连续的井，一个成功的概率是多少，这是在钻5口井，6口井等之后单个成功的概率。</span><span class="yiyi-st" id="yiyi-45">？</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">negative_binomial</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mi">100000</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">11</span><span class="p">):</span>
<span class="gp">... </span>   <span class="n">probability</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">s</span><span class="o">&lt;</span><span class="n">i</span><span class="p">)</span> <span class="o">/</span> <span class="mf">100000.</span>
<span class="gp">... </span>   <span class="nb">print</span> <span class="n">i</span><span class="p">,</span> <span class="s2">&quot;wells drilled, probability of one success =&quot;</span><span class="p">,</span> <span class="n">probability</span>
</pre></div>
</div>
</dd></dl>
